// customVideo.js
import Quill from 'quill'
 
const BlockEmbed = Quill.import('blots/block/embed')
 
class VideoBlot extends BlockEmbed {
  static create(value) {
    let node = super.create()
    node.setAttribute('src', value)
    return node
  }
 
  static value(node) {
    return node.getAttribute('src')
  }
}
 
VideoBlot.blotName = 'video'
VideoBlot.tagName = 'video'
Quill.register(VideoBlot)
 
export default {
  // 插入视频的方法
  insertVideo(value, quill) {
    const range = quill.getSelection()
    if (range) {
      quill.insertEmbed(range.index, 'video', value, 'user')
      quill.setSelection(range.index + 1, 'user')
    } else {
      quill.setSelection(quill.getLength(), 'user')
      quill.insertEmbed(quill.getLength(), 'video', value)
      quill.setSelection(quill.getLength(), 'user')
    }
  }
}